//
//  ViewController.m
//  HTTPParse
//
//  Created by 金玉龙 on 15/12/23.
//  Copyright © 2015年 jinyulong. All rights reserved.
//

#import "ViewController.h"
#import "HTMLNode.h"
#import "TFHpple.h"

@interface ViewController ()

@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, strong) NSArray *firstChildren;
@end

@implementation ViewController

@synthesize dataArray = _dataArray;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"htmlTest" ofType:@"html"];
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    TFHpple *hpple = [TFHpple hppleWithHTMLData:data];
    self.dataArray = [hpple searchWithXPathQuery:@"//p"];
    for (TFHppleElement *element in self.dataArray) {
        self.firstChildren = element.children;
        NSLog(@"%@",self.firstChildren);
//        NSLog(@"\n%@\n%@\n%@\n%@\n%@\n",self.firstChildren,element.raw,element.content,element.tagName,element.attributes);
    }
}

- (void)setDataArray:(NSArray *)dataArray{
    if (_dataArray != dataArray) {
        _dataArray = dataArray;
//        NSLog(@"%@",dataArray);
    }
}

- (NSArray *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [NSArray array];
    }
    return _dataArray;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
